<?php
namespace my;
/**
 * 前端静态类
 * 前端交互，错误捕捉
 * @author xls
 */
class Front{
    public static $error  = [];
    public static $config = [
        //业务参数
        'r'     => 0,
        'code'  => 200,
        'msg'   => '',
        'name'  => '',
        'data'  => '',
        'js'    => '',
        'url'  => '',
    ];

    public static function error($msg='操作错误！',$name='nokey'){
        self::$config['r'] = 1;
        self::$config['msg'] = $msg;
        self::$config['name'] = $name;
        return false;
    }

    public static function check( $config = []){
        $temp = [
            'err_js' => 'error',
            'suc_msg' => '操作成功!',
        ];
        $config = array_merge($temp,$config);
        if(self::$config['r']==1){
            if(isset($config['err_msg']))
              self::$config['msg'] = $config['err_msg'];
            if(isset($config['err_js']))
              self::$config['js'] = $config['err_js'];
            if(isset($config['err_url']))
              self::$config['url'] = $config['err_url'];
        }else{
            if(isset($config['suc_msg']))
              self::$config['msg'] = $config['suc_msg'];
            if(isset($config['suc_js']))
              self::$config['js'] = $config['suc_js'];
            if(isset($config['suc_url']))
              self::$config['url'] = $config['suc_url'];
        }
        if(isset($config['data'])){
            self::$config['data'] = $config['data'];
        }
        exit(json_encode(self::$config));
    }
}
